﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Home.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<%@ Import Namespace="XDeal.DAL.Entities" %>
<%@ Import Namespace="XDeal.Common.Constants" %>
<%@ Import Namespace="Utility" %>
<%@ Import Namespace="Utility.Enums" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <div id="divDealGanNhat">
        <div class="divRow">
            <%List<Deal> lstDeal = ViewData[ConstViewDataName.ListOfDeal] as List<Deal>;
              if (lstDeal != null)
              {
                  double percent = 0;
                  double newPrice = 0;
                  double oldPrice = 0;
                  int dealID = 0;
                  int totalOrder = 0;
                  string dealName = string.Empty;
                  foreach (Deal ob in lstDeal)
                  {
                      dealID = ob.ID_i;
                      oldPrice = ConvertManage.ConvertToDouble(ob.OldPrice_db, 0);
                      percent = ConvertManage.ConvertToDouble(ob.DiscountPercent_i, 0);
                      totalOrder = ob.OrderDetails.Count();
                      
                      dealName = ob.Name_s.Substring(0, 150);
                      int indexSpace = dealName.LastIndexOf(" ");
                      dealName = dealName.Substring(0, indexSpace) + "...";
                      
                      DealStatus dealStatus = DealStatus.Open;
                      if (totalOrder >= ob.CurrentQuantity_i || ob.Status_i == ConvertManage.ConvertToInt(DealStatus.SoldOut, 1))
                          dealStatus = DealStatus.SoldOut;
                      if (ob.EndDate_dt <= DateTime.Now || ob.Status_i == ConvertManage.ConvertToInt(DealStatus.Expires, 2))
                          dealStatus = DealStatus.Expires;
            %>
            <div class="divColumn">
                <div class="divTitle">
                    <h1>
                        <a href="<%: Url.Content("~/ThongTinDeal/" + ob.ID_i + "/" + ConvertManage.GetSHTMLName(ob.ShortName_s))%>"
                            title="Xem chi tiết">
                            <%:dealName%>
                        </a>
                    </h1>
                </div>
                <div class="divImage">
                    <%if (dealStatus == DealStatus.Expires)
                      {%>
                    <div class="divHetHan">
                    </div>
                    <%}
                      else if (dealStatus == DealStatus.SoldOut)
                      {%>
                    <div class="divChayHang">
                    </div>
                    <%}%>
                    <a href="<%: Url.Content("~/ThongTinDeal/" + ob.ID_i + "/" + ConvertManage.GetSHTMLName(ob.ShortName_s))%>">
                        <img src="<%= Url.Content("~/Content/upload/ListOfDealImg/" + ob.SmallImage_s)%>"
                            alt="" />
                    </a>
                </div>
                <div class="divPrice">
                    <div class="divLeft">
                        <div class="divRow">
                            <div class="t">
                                Giá trị:</div>
                            <div class="v">
                                <%:ConvertManage.ConvertToCurrency(oldPrice)%>
                                VNĐ</div>
                        </div>
                        <div class="clear">
                        </div>
                        <div class="divRow">
                            <div class="t">
                                Tiết kiệm:</div>
                            <div class="v1">
                                <%:ConvertManage.ConvertToCurrency(oldPrice - newPrice)%>
                                VNĐ</div>
                        </div>
                        <div class="clear">
                        </div>
                        <div class="divRow">
                            <div class="t">
                                Còn lại:</div>
                            <div class="v2">
                                <%:ConvertManage.ConvertToCurrency(newPrice)%>
                                VNĐ</div>
                        </div>
                    </div>
                    <div class="divRight">
                        <div class="divPercent">
                            <span>
                                <%:percent%>% </span>
                        </div>
                    </div>
                </div>
                <div class="clear">
                </div>
                <div class="divCountOrder">
                    <div class="t">
                        Đã có <span class="v" id="Span4">
                            <%:totalOrder%></span> người mua giá tốt</div>
                </div>
                <div class="clear">
                </div>
            </div>
            <%}
              }
            %>
        </div>
        <div class="clear">
        </div>
        <div class="divPager">
            <div>
                <%=ViewData[ConstViewDataName.PagerLinkDeal]%>
            </div>
        </div>
        <div class="clear">
        </div>
    </div>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="HeaderContent" runat="server">
    <link href="<%= Url.Content("~/Content/DefaultTheme/css/ListOfDeals.css")%>" rel="stylesheet"
        type="text/css" />
    <link href="<%= Url.Content("~/Content/DefaultTheme/css/Pager.css")%>" rel="stylesheet" type="text/css" />
    <script src="<%= Url.Content("~/Content/js/Commons/JSFrontEndMenu.js")%>" type="text/javascript"></script>
    <script src="<%= Url.Content("~/Content/js/ListOfDeal/JsListOfDeal.js")%>" type="text/javascript"></script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="RightContent" runat="server">
</asp:Content>
